#include <REGX52.H>
#include "DELAY.h"
#include "KEY.h"
#include "TIMER0.h"
#include "NIXIE.h"

sbit Moter=P1^0;

unsigned char Counter,Compare;//计数值和比较值，用于输出PWM
unsigned char KeyNum,Speed;

void main()
{
	
	Timer0_Init();
	while(1)
	{
		KeyNum=Key();
		if(KeyNum==1)
		{
			Speed++;
			Speed%=4;
			if(Speed==0)Compare=0;//设置比较值，改变PWM占空比
			if(Speed==1)Compare=50;
			if(Speed==2)Compare=75;
			if(Speed==3)Compare=100;
		}
		Nixie(1,Speed);
	}
}

//每隔100us进来一次
void Timer0_Routine() interrupt 1
{
	TL0 = 0x9C;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
	Counter++;
	Counter%=100;//Counter范围是1~100,100*100us=10ms,T=10ms
	if(Counter<Compare)Moter=1;
	else Moter=0;
}